<?php
require_once 'Zend/Db/Table/Abstract.php';
class Model_OrderMapper extends Zend_Db_Table_Abstract
{
	protected $_name='order';
	protected $_primary='OrdID';

	
	public function getAllCategories()
	{
		$rowset=$this->fetchAll();
		$rowcount= count($rowset);
		$result=array();
		$i=0;
		if ($rowcount >0)
		{
			foreach($rowset as $row)
			{
				$i=$i+1;
				$name = $row->Name;
				$id = $row->CatID;
				$description=$row->Description;
				$cat=new Model_Category();
				$cat->setId($id)->setName($name)->setDescription($description);
				$result[$i]=$cat;
			}
			
		}
		return $result;
	}
	
	public function getTopCategories()
	{
		$rowset=$this->fetchAll();
		$rowcount= count($rowset);
		$result=array();
		$i=0;
		if ($rowcount >0)
		{
			foreach($rowset as $row)
			{
				$i=$i+1;
				$name = $row->Name;
				$id = $row->CatID;
				$description=$row->Description;
				$cat=new Model_Category();
				$cat->setId($id)->setName($name)->setDescription($description);
				$result[$i]=$cat;
				if ($i>5) return $result;
			}
				
		}
		return $result;
	}
	
	
	public function getCategory($catId)
	{
		$row=$this->fetchRow($this->select()->where('CatID=?',$catId));
		$result=new Model_Category();
		if($row)
		{
			$name=$row->Name;
			$id=$row->CatID;
			$description=$row->Description;
			$result->setId($id)->setName($name)->setDescription($description);
		}
		return $result;
	}
	
	
	
	public function createOrder(Model_Order $order)
	{
		try {
			$data = array('LocID' => $order->getLocationId(),
				'CusID' => $order->getCustomerId(),	
				'DelID' => $order->getDeliveryId(),				
				'AdressShip' => $order->getAddressShip(),
				'DateCreate'=>$order->getDateCreate(),
				'Total'=>$order->getTotal()
		);
			$this->insert($data);
			return "da tao";
		} catch (Exception $e) {
			return "error";
		}
	
	}
	
	
}